package com.ruoyi.cderp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cderp.domain.TblLogisticsSheet;
import com.ruoyi.cderp.service.ITblLogisticsSheetService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物流单Controller
 *
 * @author ruoyi
 * @date 2025-04-25
 */
@RestController
@RequestMapping("/system/TblLogisticsSheet")
public class TblLogisticsSheetController extends BaseController
{
    @Autowired
    private ITblLogisticsSheetService tblLogisticsSheetService;

    /**
     * 查询物流单列表
     */
    @PreAuthorize("@ss.hasPermi('system:TblLogisticsSheet:list')")
    @GetMapping("/list")
    public TableDataInfo list(TblLogisticsSheet tblLogisticsSheet)
    {
        startPage();
        List<TblLogisticsSheet> list = tblLogisticsSheetService.selectTblLogisticsSheetList(tblLogisticsSheet);
        return getDataTable(list);
    }

    /**
     * 导出物流单列表
     */
    @PreAuthorize("@ss.hasPermi('system:TblLogisticsSheet:export')")
    @Log(title = "物流单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TblLogisticsSheet tblLogisticsSheet)
    {
        List<TblLogisticsSheet> list = tblLogisticsSheetService.selectTblLogisticsSheetList(tblLogisticsSheet);
        ExcelUtil<TblLogisticsSheet> util = new ExcelUtil<TblLogisticsSheet>(TblLogisticsSheet.class);
        util.exportExcel(response, list, "物流单数据");
    }

    /**
     * 获取物流单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:TblLogisticsSheet:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tblLogisticsSheetService.selectTblLogisticsSheetById(id));
    }

    /**
     * 新增物流单
     */
    @PreAuthorize("@ss.hasPermi('system:TblLogisticsSheet:add')")
    @Log(title = "物流单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TblLogisticsSheet tblLogisticsSheet)
    {
        return toAjax(tblLogisticsSheetService.insertTblLogisticsSheet(tblLogisticsSheet));
    }

    /**
     * 修改物流单
     */
    @PreAuthorize("@ss.hasPermi('system:TblLogisticsSheet:edit')")
    @Log(title = "物流单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TblLogisticsSheet tblLogisticsSheet)
    {
        return toAjax(tblLogisticsSheetService.updateTblLogisticsSheet(tblLogisticsSheet));
    }

    /**
     * 删除物流单
     */
    @PreAuthorize("@ss.hasPermi('system:TblLogisticsSheet:remove')")
    @Log(title = "物流单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tblLogisticsSheetService.deleteTblLogisticsSheetByIds(ids));
    }

    // 根据业务id（销售出库id）查询物流单是否发货
    @PreAuthorize("@ss.hasPermi('system:TblLogisticsSheet:isDelivery')")
    @GetMapping("/isDelivery/{id}")
    public int isDelivery(@PathVariable("id") String id)
    {
    	return tblLogisticsSheetService.isDelivery(id);
    }
}
